package com.example.myapp;

import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;

public class MyApplication extends Application {
    public static final String CHANNEL_ID = "message_channel";
    @Override
    public void onCreate() {
        super.onCreate();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            // 创建一个通知渠道
            NotificationChannel channel = new NotificationChannel(
                    CHANNEL_ID,
                    "消息通知",
                    NotificationManager.IMPORTANCE_DEFAULT
            );
            channel.setDescription("用于接收各种消息的通知渠道");
            // 获取系统的通知管理器服务
            NotificationManager manager = getSystemService(NotificationManager.class);
            // 创建通知渠道
            manager.createNotificationChannel(channel);
        }
    }
}
